<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>财务信息</title>

    <!-- Bootstrap Core CSS -->
    <link th:href="@{/vendor/bootstrap/css/bootstrap.min.css}" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link th:href="@{/vendor/metisMenu/metisMenu.min.css}" rel="stylesheet">

    <!-- Custom CSS -->
    <link th:href="@{/dist/css/sb-admin-2.css}" rel="stylesheet">

    <!-- Custom Fonts -->
    <link th:href="@{/vendor/font-awesome/css/font-awesome.min.css}" rel="stylesheet" type="text/css">

    <link th:href="@{/vendor/datepicker/datepicker3.css}" rel="stylesheet" type="text/css">

    <!--bootstrap-table CSS-->
    <link th:href="@{vendor/bootstrap/css/bootstrap-table.css}" rel="stylesheet" type="text/css">

    <!--bootstrap-fileinput CSS-->
    <link th:href="@{vendor/bootstrap-fileinput/css/fileinput.min.css}" rel="stylesheet" type="text/css">

    <!-- jQuery -->
    <script th:src="@{/vendor/jquery/jquery.min.js}"></script>

    <!-- Bootstrap Core JavaScript -->
    <script th:src="@{/vendor/bootstrap/js/bootstrap.min.js}"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script th:src="@{/vendor/metisMenu/metisMenu.min.js}"></script>

    <!-- Custom Theme JavaScript -->
    <script th:src="@{/dist/js/sb-admin-2.js}"></script>

    <script th:src="@{/vendor/datepicker/bootstrap-datepicker.js}"></script>

    <!--jquery-form JavaScript-->
    <script th:src="@{vendor/jquery/jquery.form.min.js}"></script>

    <!--bootstrap-table JavaScript-->
    <script th:src="@{vendor/bootstrap/js/bootstrap-table.js}"></script>

    <!--bootstrap-fileinput JavaScript-->
    <script th:src="@{vendor/bootstrap-fileinput/js/fileinput.min.js}"></script>

    <!--bootstrap-fileinput-zh JavaScript-->
    <script th:src="@{vendor/bootstrap-fileinput/js/zh.js}"></script>

    <script>

        $(function () {
            //ajax 方式上传文件操作
            $(document).ready(function(){
                $('#save').click(function(){
                    if(checkData()){
                        var custcode = $("#custcode").val();
                        $.ajax({
                            type: "POST",
                            url: "/finance_insertCheck",
                            contentType: "application/json",
                            dataType: "html",
                            data: JSON.stringify({
                                custcode: custcode.toString()
                            }),
                            success: function (result) {
                                if (result == "0"){
                                    alert("导入excel成功");
                                    return result;
                                }else {
                                    alert("导入excel出错，该文件数据已存在！");
                                    return result;
                                }
                            },
                            error:function () {
                                alert("导入excel出错！");
                            }
                        });
//                        $('#financeHeaderForm').ajaxSubmit({
//                            name: "finance_file",
//                            type: "POST",
//                            url:'financeInfo',
//                            dataType: 'text',
//                            success: resutlMsg,
//                            error: errorMsg
//                        });
//                        function resutlMsg(msg){
//                            alert(msg);
//                            $("#finance_file").val("");
//                        }
//                        function errorMsg(){
//                            alert("导入excel出错！");
//                        }
                    }
                });
            });

            //JS校验form表单信息
            function checkData(){
                var fileDir = $("#finance_file").val();
                var suffix = fileDir.substr(fileDir.lastIndexOf("."));
                if("" == fileDir){
                    alert("选择需要导入的Excel文件！");
                    return false;
                }
                if(".xls" != suffix && ".xlsx" != suffix ){
                    alert("选择Excel格式的文件导入！");
                    return false;
                }
                return true;
            }
        });

        //格式化金额
        function outputdollars(number) {
            if (number.length <= 3)
                return (number == '' ? '0' : number);
            else {
                var mod = number.length % 3;
                var output = (mod == 0 ? '' : (number.substring(0, mod)));
                for (i = 0; i < Math.floor(number.length / 3); i++) {
                    if ((mod == 0) && (i == 0))
                        output += number.substring(mod + 3 * i, mod + 3 * i + 3);
                    else
                        output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
                }
                return (output);
            }
        }
        function outputcents(amount) {
            amount = Math.round(((amount) - Math.floor(amount)) * 100);
            return (amount < 10 ? '.0' + amount : '.' + amount);
        }

        $(function () {
            function headerQueryParams(params) {
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    //                    limit: params.limit,   //页面大小
                    //                    offset: params.offset,  //页码
                    custcode: $("#custcode").val()
                    //                    statu: $("#txt_search_statu").val()
                };
                return temp;
            }

            function bodyQueryParams(params) {
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    //                    limit: params.limit,   //页面大小
                    //                    offset: params.offset,  //页码
                    custcode: $("#custcode").val()
                    //                    statu: $("#txt_search_statu").val()
                };
                return temp;
            }

            $('#tb_headerinfo').bootstrapTable({
                url: '/financeHeaderInfo_Search',         //请求后台的URL（*）
                method: 'post',                      //请求方式（*）
//                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                queryParams: headerQueryParams,//传递参数（*）
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber:1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                showToggle:true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [{
                    checkbox: true
                }, {
                    field: 'typeid',
                    title: '类型'
                }, {
                    field: 'reportno',
                    title: '报表编号'
                }, {
                    field: 'reportdate',
                    title: '报表起始日',
                    formatter:function(value,row,index){
                        if (value != null) {
                            var date = new Date(parseInt(value));
                            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                            return "" + date.getFullYear()  + month  + currentDate;
                        }
                    }
                }, {
                    field: 'reportenddate',
                    title: '报表结束日',
                    formatter:function(value,row,index){
                        if (value != null) {
                            var date = new Date(parseInt(value));
                            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                            return "" + date.getFullYear()  + month  + currentDate;
                        }
                    }
                }, {
                    field: 'auditoffice',
                    title: '审计事务所'
                }, {
                    field: 'audittime',
                    title: '审计日期',
                    formatter:function(value,row,index){
                        if (value != null) {
                            var date = new Date(parseInt(value));
                            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                            return "" + date.getFullYear()  + month  + currentDate;
                        }
                    }
                } ],

//                onClickRow:function (row) {
//                    $("#ethnic").val(row.ethnic);
//                    $("#custNo").val(row.custNo);
//                    $("#lastName").val(row.lastName);
//                    $("#hierarchy").val(row.hierarchy);
//                    $("#holdcustomershareratio").val(row.holdcustomershareratio);
//                    $("#customerholdshareratio").val(row.customerholdshareratio);
//                }

            });

            $('#tb_bodyinfo').bootstrapTable({
                url: '/financeBodyInfo_Search',         //请求后台的URL（*）
                method: 'post',                      //请求方式（*）
//                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                queryParams: bodyQueryParams,//传递参数（*）
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber:1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                showToggle:true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [{
                    checkbox: true
                }, {
                    field: 'seqno',
                    title: '顺序号'
                }, {
                    field: 'typeid',
                    title: '科目名称'
                }, {
                    field: 'origvalue',
                    title: '期初值',
                    formatter:function(value,row,index){
                        if (value != null) {
                            if (value < 0) {
                                return '-' + outputdollars(Math.floor(Math.abs(value) - 0) + '') + outputcents(Math.abs(value) - 0);
                            } else {
                                return outputdollars(Math.floor(value - 0) + '') + outputcents(value - 0);
                            }
                        }
                    }
                }, {
                    field: 'endvalue',
                    title: '期末值',
                    formatter:function(value,row,index){
                        if (value != null) {
                            if (value < 0) {
                                return '-' + outputdollars(Math.floor(Math.abs(value) - 0) + '') + outputcents(Math.abs(value) - 0);
                            } else {
                                return outputdollars(Math.floor(value - 0) + '') + outputcents(value - 0);
                            }
                        }
                    }
                } ],

//                onClickRow:function (row) {
//                    $("#ethnic").val(row.ethnic);
//                    $("#custNo").val(row.custNo);
//                    $("#lastName").val(row.lastName);
//                    $("#hierarchy").val(row.hierarchy);
//                    $("#holdcustomershareratio").val(row.holdcustomershareratio);
//                    $("#customerholdshareratio").val(row.customerholdshareratio);
//                }

            });

        })
    </script>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

<div id="wrapper">
    <div id="page-wrapper" style="margin-left: 0px;">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">财务信息</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!--  <form  th:action="@{/app}"  th:object="${apply_entity}" method="post">  -->
        <form id="financeHeaderForm" name="financeHeaderForm" method="post"  th:action="@{/financeInfo(custcode=${custcode})}" th:object="${finance_header_entity}" >
            <div class="panel-group" id="accordion">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <div class="row">
                                <div class="col-lg-2">
                                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">财务信息</a>
                                    <button type="submit" id="save" class="btn btn-primary">上  载</button>
                                </div>
                            </div>
                        </h4>
                    </div>
                    <div id="collapseOne" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-6">
                                    <div class="col-lg-4">
                                        <label class="control-label">上传文件名：</label>
                                    </div>
                                    <div class="col-lg-8">
                                        <input id="finance_file" name="finance_file" type="file" multiple class="file"  data-show-upload="false" data-show-caption="true">
                                    </div>
                                </div>
                            </div>
                            <div style="display:none;">
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="col-lg-4">
                                            <label>客户号：</label>
                                        </div>
                                        <div class="col-lg-8">
                                            <input class="form-control" th:field="*{custcode}" id="custcode" name="custcode" maxlength="20">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="col-lg-4">
                                            <label>类型：</label>
                                        </div>
                                        <div class="col-lg-8">
                                            <input class="form-control" th:field="*{typeid}" id="typeid" name="typeid" maxlength="20">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="col-lg-4">
                                            <label>报表编号(表头)：</label>
                                        </div>
                                        <div class="col-lg-8">
                                            <input class="form-control" th:field="*{reportno}" id="reportno_header" name="reportno_header" maxlength="20">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="col-lg-4">
                                            <label>报表起始日：</label>
                                        </div>
                                        <div class="col-lg-8">
                                            <input class="form-control" th:field="*{reportdate}" id="reportdate" name="reportdate" maxlength="20">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="col-lg-4">
                                            <label>报表结束日：</label>
                                        </div>
                                        <div class="col-lg-8">
                                            <input class="form-control" th:field="*{reportenddate}" id="reportenddate" name="reportenddate" maxlength="20">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="col-lg-4">
                                            <label>审计事务所：</label>
                                        </div>
                                        <div class="col-lg-8">
                                            <input class="form-control" th:field="*{auditoffice}" id="auditoffice" name="auditoffice" maxlength="20">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="col-lg-4">
                                            <label>审计日期：</label>
                                        </div>
                                        <div class="col-lg-8">
                                            <input class="form-control" th:field="*{audittime}" id="audittime" name="audittime" maxlength="20">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="col-lg-4">
                                            <label>审计人：</label>
                                        </div>
                                        <div class="col-lg-8">
                                            <input class="form-control" th:field="*{auditofficer}" id="auditofficer" name="auditofficer" maxlength="20">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="panel panel-default">
                                <div class="panel-heading"></div>
                                <div class="panel-body">
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <table id="tb_headerinfo"></table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <form id="financeBodyForm" name="financeBodyForm" method="post"  th:action="@{/financeInfo(custcode=${custcode})}" th:object="${finance_body_entity}" >
            <div style="display:none;">
                <div class="row">
                    <div class="col-lg-6">
                        <div class="col-lg-4">
                            <label>报表编号(表体)：</label>
                        </div>
                        <div class="col-lg-8">
                            <input class="form-control" th:field="*{reportno}" id="reportno_body" name="reportno_body" maxlength="20">
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6">
                        <div class="col-lg-4">
                            <label>顺序号：</label>
                        </div>
                        <div class="col-lg-8">
                            <input class="form-control" th:field="*{seqno}" id="seqno" name="seqno" maxlength="20">
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6">
                        <div class="col-lg-4">
                            <label>科目名称：</label>
                        </div>
                        <div class="col-lg-8">
                            <input class="form-control" th:field="*{typeid}" id="detail_typeid" name="detail_typeid" maxlength="20">
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6">
                        <div class="col-lg-4">
                            <label>期初值：</label>
                        </div>
                        <div class="col-lg-8">
                            <input class="form-control" th:field="*{origvalue}" id="origvalue" name="origvalue" maxlength="20">
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6">
                        <div class="col-lg-4">
                            <label>期末值：</label>
                        </div>
                        <div class="col-lg-8">
                            <input class="form-control" th:field="*{endvalue}" id="endvalue" name="endvalue" maxlength="20">
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading"></div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-lg-12">
                            <table id="tb_bodyinfo"></table>
                        </div>
                    </div>
                </div>
            </div>
        </form>




    </div>
    <!-- /#page-wrapper -->

</div>




<!-- /#wrapper -->


</body>

</html>
